<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui" template="/paginas/template.xhtml">

	<ui:define name="corpoForm">
		

		<h:form id="formBotoesVenda" prependId="false">
			<p:panelGrid columns="1" styleClass="botoes" id="botoes">
				<p:commandButton id="botaoCriarVenda" value="#{rsc.label_criar}"  rendered="#{p:ifGranted('CRIAR_VENDA')}" 
					styleClass="botao" action="#{manterVendaBean.criarEntidade}"
					ajax="false" title="#{rsc.title_criar}" />
			</p:panelGrid>
		</h:form>

		<f:event type="javax.faces.event.PreRenderComponentEvent"
			listener="#{manterVendaBean.preRenderList}" />
		<h:form id="formListVendas" prependId="false">
			<p:fieldset legend="#{rsc.label_filtros}" toggleable="true"
				collapsed="true">


				<p:panelGrid columns="4">
					<p:outputLabel value="#{rsc.label_codigo}" for="txtCodigoVenda" />

					<p:outputLabel value="#{rsc.label_produto}: " for="acProduto" />

					<p:outputLabel value="#{rsc.label_status}" for="cmbStatus" />

					<p:spacer />

					<p:inputText styleClass="numerico9" id="txtCodigoVenda"
						value="#{manterVendaBean.filtro.codigo}" />

					<p:autoComplete id="acProduto" minQueryLength="3"
						value="#{manterVendaBean.filtro.nomeProduto}"
						effect="fade" maxResults="7" size="32"
						completeMethod="#{manterVendaBean.autoCompleteProdutoNome}">
						<p:ajax event="change"
							listener="#{manterVendaBean.buscarPorFiltros}"
							update="listaVendas" />
					</p:autoComplete>

					<p:selectOneMenu label="#{rsc.label_status}"
						value="#{manterVendaBean.filtro.status}"
						id="cmbStatus">
						<p:ajax event="change"
							listener="#{manterVendaBean.buscarPorFiltros}"
							update="listaVendas" />
						<f:selectItem itemLabel="#{rsc.label_selecionar}" itemValue="" />
						<f:selectItems
							value="#{manterVendaBean.formulario.listaStatus}"
							var="c" itemLabel="#{c.label}" itemValue="#{c}" />
					</p:selectOneMenu>

					<p:commandButton update="listaVendas"
						actionListener="#{manterVendaBean.buscarPorFiltros}"
						icon="ui-icon ui-icon-search" title="#{rsc.label_buscar}" />

				</p:panelGrid>
			</p:fieldset>

			<p:panel id="pnlListaVendas" header="#{rsc.label_vendasCadastradas}"
				toggleable="true" toggleSpeed="500">
				<p:panelGrid columns="1" styleClass="full-width"
					columnClasses="full-width">
					<p:dataTable emptyMessage="#{msg.nenhumRegistroEncontrado}"
						var="venda" id="listaVendas" value="#{manterVendaBean.entidades}"
						paginator="true" rows="10"
						paginatorPosition="#{rsc.label_paginationPosition}"
						paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
						rowsPerPageTemplate="10,50,150,200">

						<p:column headerText="#{rsc.label_codigo}">
							<p:outputLabel value="#{venda.id}" />
						</p:column>


						<p:column headerText="#{rsc.label_tipoVenda}" sortBy="#{venda.tipoVenda.label}">
							<h:outputText value="#{venda.tipoVenda.label}" />
						</p:column>

						<p:column headerText="#{rsc.label_dataVenda}" sortBy="#{venda.dataVenda}">
							<h:outputText value="#{venda.dataVenda}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputText>
						</p:column>

						<p:column headerText="#{rsc.label_status}" sortBy="#{venda.statusVenda}">
							<h:outputText value="#{venda.statusVenda.label}" />
						</p:column>

						<p:column headerText="#{rsc.label_valorBruto}" sortBy="#{venda.valorBruto}">
							<h:outputText value="#{venda.valorBruto}"
								converter="bigDecimalConverter" />
						</p:column>

						<p:column styleClass="coluna-acoes"
							headerText="#{rsc.label_acoes}">

							<p:commandButton icon="ui-icon ui-icon-pencil" rendered="p:ifGranted('ALTERAR_VENDA')"
								title="#{rsc.label_editar}" ajax="false" action="editarVenda">
								<f:setPropertyActionListener value="#{venda}"
									target="#{manterVendaBean.entidade}" />
							</p:commandButton>

						</p:column>
					</p:dataTable>
				</p:panelGrid>
			</p:panel>
		</h:form>

		<p:confirmDialog message="#{msg.questionConfirmaRemover}"
			appendTo="@(body)" width="250" id="removeDialog"
			header="#{rsc.label_confirmar}" severity="alert"
			widgetVar="confirmacao">
			<h:form id="confirmarForm">
				<p:commandButton value="#{rsc.label_sim}"
					actionListener="#{manterVendaBean.remover}"
					oncomplete="confirmacao.hide()"
					update=":formListVendas:listaVendas" />
				<p:commandButton value="#{rsc.label_nao}"
					onclick="confirmacao.hide()" type="button" />
			</h:form>
		</p:confirmDialog>

	</ui:define>
</ui:composition>

